<template>
    <div class="app-container calendar-list-container" v-loading="loading" element-loading-text="正在导出数据">
    <!-- filter 条件查询 -->
    <div class="btn-add">
        <el-button
        icon="el-icon-circle-plus-outline"
        type="button"
        class="el-button el-button--primary"
        @click="showAdd = true"
        >
            新增</el-button
        >
    </div>

    <!-- 新增数据弹窗 -->
    <el-dialog
      title="新增"
      :visible.sync="showAdd"
      @close="showAdd = false"
      width="75%"
    >
        <el-row :gutter="10">
            <el-form :inline="true" :model="createForm" ref="createForm" :rules="addRules" label-width="120px">
                <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                    <el-form-item label="资源大类" prop="facilityBarcodeType1">
                        <el-select
                            v-model="createForm.facilityBarcodeType1"
                            style="width:180px"
                            @focus="getBarcodeType('大类')">
                            <el-option
                                v-for="(item,index) in barcodeType1List"
                                :key="index"
                                :label="item.facilityBarcodeName"
                                :value="item.facilityBarcodeName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="资源属性" prop="facilityBarcodeType4">
                        <el-select
                            v-model="createForm.facilityBarcodeType4"
                            style="width:180px"
                            @focus="getBarcodeType('属性')">
                            <el-option
                                v-for="(item,index) in barcodeType4List"
                                :key="index"
                                :label="item.facilityBarcodeName"
                                :value="item.facilityBarcodeName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="工装名称" prop="facilityName">
                        <el-input v-model="createForm.facilityName" style="width: 180px" />
                    </el-form-item>
                    <el-form-item label="资源来源">
                        <el-select
                            clearable
                            v-model="createForm.resourceSource"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsResourceSourceList"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="资源类型">
                        <el-select
                            clearable
                            v-model="createForm.resourceType"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsResourceTypeList"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="点检审核" prop="spotAudit">
                        <el-select
                            v-model="createForm.spotAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="是否需要点检" prop="isSpot">
                        <el-select
                            v-model="createForm.isSpot"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>

                </el-col>
                <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                    <el-form-item label="资源小类" prop="facilityBarcodeType2">
                        <el-select
                            v-model="createForm.facilityBarcodeType2"
                            style="width:180px"
                            @focus="getBarcodeType('小类')">
                            <el-option
                                v-for="(item,index) in barcodeType2List"
                                :key="index"
                                :label="item.facilityBarcodeName"
                                :value="item.facilityBarcodeName">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="上限次数" prop="upperLimitNumber" >
                        <el-input v-model="createForm.upperLimitNumber" style="width: 180px" />
                    </el-form-item>

                    <el-form-item label="工装生产日期" prop="facilityProductionDate" >
                        <el-date-picker
                            v-model="createForm.facilityProductionDate"
                            type="datetime"
                            placeholder="选择日期时间"
                            align="right"
                            format="yyyy-MM-dd HH:mm"
                            value-format="yyyy-MM-dd HH:mm"
                            style="width: 180px" >
                        </el-date-picker>
                    </el-form-item>

                    <el-form-item label="验收审核" prop="acceptanceAudit">
                        <el-select
                            v-model="createForm.acceptanceAudit"
                             style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="维修审核" prop="maintenanceAudit">
                        <el-select
                            v-model="createForm.maintenanceAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="报废审核" prop="retirementAudit">
                        <el-select
                            v-model="createForm.retirementAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>

                </el-col>
                <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                    <el-form-item label="资源规格" prop="facilityBarcodeType3">
                        <el-select
                        filterable
                            v-model="createForm.facilityBarcodeType3"
                            style="width:180px"
                            @focus="getBarcodeType('规格')">
                            <el-option
                                v-for="(item,index) in barcodeType3List"
                                :key="index"
                                :label="item.facilityBarcodeName"
                                :value="item.facilityBarcodeName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="上限时间" prop="upperLimitDate" >
                        <el-date-picker
                            v-model="createForm.upperLimitDate"
                            type="datetime"
                            placeholder="选择日期时间"
                            align="right"
                            format="yyyy-MM-dd HH:mm"
                            value-format="yyyy-MM-dd HH:mm"
                            style="width:180px">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="维护保养人工号" prop="jobNumber" >
                        <el-select filterable v-model="createForm.jobNumber" style="width:180px" @change="jobNumberChange($event,1)">
                            <el-option
                                v-for="(item,index) in userList"
                                :key="index"
                                :label="item.jobNumber"
                                :value="item.jobNumber">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="维护保养人姓名" prop="userName" >
                        <el-select filterable v-model="createForm.userName" style="width:180px" @change="NameChange($event,1)">
                            <el-option
                                v-for="(item,index) in userList"
                                :key="index"
                                :label="item.userName"
                                :value="item.userName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="出入库审核" prop="accessAudit">
                        <el-select
                            v-model="createForm.accessAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="外校审核" prop="externalSchoolAudit">
                        <el-select
                            v-model="createForm.externalSchoolAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-form :inline="true" :model="createForm" ref="createForm3" label-width="120px" :rules="addRules" v-if="createForm.isSpot == '是'">
            <el-form-item label="点检频次" prop="spotFrequency">
                <!-- Cron表达式：<el-input readonly clearable v-model="createForm.spotFrequency" :style="{ width: inputWid(createForm.spotFrequency) }"/>。 -->
                <div>
                每 <el-input v-model.number="frequency.times" :readonly="frequency.date == '年'?true:false" type="number" style="width:70px" @blur="setSpot('times','add')"/>
                <el-select
                    v-model="frequency.date"
                    style="width:70px"
                    @change="setSpot('date','upd')">
                    <el-option
                        v-for="(item,index) in optionsDate"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select>
                <el-select
                  v-if="frequency.date === '年'"
                    v-model="value2"
                    style="width:70px"
                    @change="changeMonth"
                    placeholder="月">
                    <el-option
                        v-for="(item,index) in 12"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select>
                <el-select
                  v-if="frequency.date === '年'"
                    v-model="value3"
                    style="width:70px"
                    @change="changeDay"
                    placeholder="日">
                    <el-option
                        v-for="(item,index) in days"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select> 执行一次</div>
            </el-form-item>
        </el-form>
        <el-form :inline="true" :model="createForm" ref="createForm2" label-width="120px">
            <el-form-item label="备注栏">
                <el-input style="width: 350px" clearable type="textarea" :autosize="{ minRows: 1, maxRows: 3}" v-model="createForm.remark" auto-complete="off"></el-input>
            </el-form-item>
        </el-form>

        <!-- 公共底部 -->
        <div slot="footer" class="dialog-footer">
            <el-button @click="showAdd = false">取 消</el-button>
            <el-button
            type="primary"
            @click="addprocess('createForm')"
            :loading="createLoading"
            >新增</el-button
            >
        </div>
    </el-dialog>


    <div class="filter-container">
      <!-- style="width: 150px;margin-right:15px;" -->
        <el-input
            @keyup.enter.native="getData"
            clearable
            style="margin-right: 15px"
            :style="{ width: inputWid(param.facilityBarcode) }"
            v-model="param.facilityBarcode"
            placeholder="工装条码"
        ></el-input>

        <el-input
            @keyup.enter.native="getData"
            clearable
            style="width: 150px;margin-right:15px;"
            v-model="param.facilityName"
            placeholder="工装名称"
        ></el-input>

        <el-button type="primary" v-waves icon="el-icon-search" @click="getData">搜索</el-button>
        <el-button
            type="button"
            v-waves
            class="el-button el-button--warning"
            @click="cancelSubmit"
        >
        重置</el-button>

    </div>

    <!-- table 表格 -->
    <el-table  :data="tableInfo" v-loading="loadingList" element-loading-text="给我一首歌的时间" stripe border fit highlight-current-row style="width: 100%;margin-top:15px;">
      <el-table-column  label="序号" type="index" align="center" width="80px"/>
      <el-table-column label="工装条码"  prop="facilityBarcode" align="center"/>
      <el-table-column label="工装名称"  prop="facilityName" align="center"/>
      <el-table-column label="工装生产日期"  prop="facilityProductionDate" align="center" width="120px"/>
      <el-table-column label="使用时间(月)"  prop="useDate" align="center" width="120px"/>
      <el-table-column label="上限时间(月)"  prop="upperLimitDate" align="center" width="120px"/>
      <el-table-column label="累计次数"  prop="cumulativeNumber" align="center"/>
      <el-table-column label="上限次数"  prop="upperLimitNumber" align="center"/>
      <el-table-column label="维护保养人工号"  prop="jobNumber" align="center" width="120px"/>
      <el-table-column label="维护保养人姓名"  prop="userName" align="center" width="120px"/>
      <el-table-column label="结果判定"  prop="type" align="center"/>
      <el-table-column label="备注栏" align="center">
        <template slot-scope="scope">
          {{scope.row.remark === 'null'? '' : scope.row.remark }}
        </template>
      </el-table-column>
      <el-table-column label="资源来源"  prop="resourceSource" align="center"/>
      <el-table-column label="资源类型"  prop="resourceType" align="center"/>
      <el-table-column label="验收审核"  prop="acceptanceAudit" align="center"/>
      <el-table-column label="出入库审核"  prop="accessAudit" align="center" width="100px"/>
      <el-table-column label="点检审核"  prop="spotAudit" align="center"/>
      <el-table-column label="维修审核"  prop="maintenanceAudit" align="center"/>
      <el-table-column label="外校审核"  prop="externalSchoolAudit" align="center"/>
      <el-table-column label="报废审核"  prop="retirementAudit" align="center"/>
      <el-table-column label="是否需要点检"  prop="isSpot" align="center" width="120px"/>
      <el-table-column label="点检频次" align="center">
        <template slot-scope="scope">
          {{scope.row.spotFrequency === 'null'? '' : scope.row.spotFrequency }}
        </template>
      </el-table-column>
      <el-table-column label="创建时间"  prop="createTime" align="center" width="120px"/>
      <el-table-column label="修改时间"  prop="updateTime" align="center" width="120px"/>
      <el-table-column label="操作" fixed="right" align="center" width="200">
            <template slot-scope="scope" >
                <div class="fx" style="display: flex">
                    <el-button size="mini" type="success" @click="handlePrint(scope.row)">打印</el-button>
                    <el-button size="mini" type="primary" @click="handleEdit(scope.row)">修改</el-button>
                    <el-button
                        icon="el-icon-delete"
                        class="el-button el-button--danger"
                        style="font-size: 15px;"
                        @click="handleDelete(scope.row,scope.$index)"
                    ></el-button>
                </div>
            </template>
      </el-table-column>
    </el-table>

    <!-- 修改数据弹窗 -->
    <el-dialog
      title="修改信息"
      :visible.sync="showupd"
      @close="showupd = false"
      width="75%"
    >
        <el-row :gutter="10">
            <el-form :inline="true" :model="updForm" ref="updForm" :rules="addRules" label-width="120px">
                <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                    <el-form-item label="资源大类" prop="facilityBarcodeType1">
                        <el-select
                            v-model="updForm.facilityBarcodeType1"
                            style="width:180px"
                            @focus="getBarcodeType('大类')">
                            <el-option
                                v-for="(item,index) in barcodeType1List"
                                :key="index"
                                :label="item.facilityBarcodeName"
                                :value="item.facilityBarcodeName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="资源属性" prop="facilityBarcodeType4">
                        <el-select
                            v-model="updForm.facilityBarcodeType4"
                            style="width:180px"
                            @focus="getBarcodeType('属性')">
                            <el-option
                                v-for="(item,index) in barcodeType4List"
                                :key="index"
                                :label="item.facilityBarcodeName"
                                :value="item.facilityBarcodeName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="工装名称" prop="facilityName">
                        <el-input v-model="updForm.facilityName" style="width: 180px" />
                    </el-form-item>
                    <el-form-item label="资源来源">
                        <el-select
                            clearable
                            v-model="updForm.resourceSource"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsResourceSourceList"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="资源类型">
                        <el-select
                            clearable
                            v-model="updForm.resourceType"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsResourceTypeList"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="点检审核" prop="spotAudit">
                        <el-select
                            v-model="updForm.spotAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="是否需要点检" prop="isSpot">
                        <el-select
                            v-model="updForm.isSpot"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>

                </el-col>
                <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                    <el-form-item label="资源小类" prop="facilityBarcodeType2">
                        <el-select
                            v-model="updForm.facilityBarcodeType2"
                            style="width:180px"
                            @focus="getBarcodeType('小类')">
                            <el-option
                                v-for="(item,index) in barcodeType2List"
                                :key="index"
                                :label="item.facilityBarcodeName"
                                :value="item.facilityBarcodeName">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="上限次数" prop="upperLimitNumber" >
                        <el-input v-model="updForm.upperLimitNumber" style="width: 180px" />
                    </el-form-item>

                    <el-form-item label="工装生产日期" prop="facilityProductionDate" >
                        <el-date-picker
                            v-model="updForm.facilityProductionDate"
                            type="datetime"
                            placeholder="选择日期时间"
                            align="right"
                            format="yyyy-MM-dd HH:mm"
                            value-format="yyyy-MM-dd HH:mm"
                            style="width: 180px" >
                        </el-date-picker>
                    </el-form-item>

                    <el-form-item label="验收审核" prop="acceptanceAudit">
                        <el-select
                            v-model="updForm.acceptanceAudit"
                             style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="维修审核" prop="maintenanceAudit">
                        <el-select
                            v-model="updForm.maintenanceAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="报废审核" prop="retirementAudit">
                        <el-select
                            v-model="updForm.retirementAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>


                </el-col>
                <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
                    <el-form-item label="资源规格" prop="facilityBarcodeType3">
                        <el-select
                        filterable
                            v-model="updForm.facilityBarcodeType3"
                            style="width:180px"
                            @focus="getBarcodeType('规格')">
                            <el-option
                                v-for="(item,index) in barcodeType3List"
                                :key="index"
                                :label="item.facilityBarcodeName"
                                :value="item.facilityBarcodeName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="上限时间" prop="upperLimitDate" >
                        <el-date-picker
                            v-model="updForm.upperLimitDate"
                            type="datetime"
                            placeholder="选择日期时间"
                            align="right"
                            format="yyyy-MM-dd HH:mm"
                            value-format="yyyy-MM-dd HH:mm"
                            style="width:180px">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item label="维护保养人工号" prop="jobNumber" >
                        <!-- <el-input v-model="updForm.jobNumber" style="width: 180px" /> -->
                        <el-select filterable v-model="updForm.jobNumber" style="width:180px" @change="jobNumberChange($event,2)">
                            <el-option
                                v-for="(item,index) in userList"
                                :key="index"
                                :label="item.jobNumber"
                                :value="item.jobNumber">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="维护保养人姓名" prop="userName" >
                        <!-- <el-input v-model="updForm.userName" style="width: 180px" /> -->
                        <el-select filterable v-model="updForm.userName" style="width:180px" @change="NameChange($event,2)">
                            <el-option
                                v-for="(item,index) in userList"
                                :key="index"
                                :label="item.userName"
                                :value="item.userName">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="出入库审核" prop="accessAudit">
                        <el-select
                            v-model="updForm.accessAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="外校审核" prop="externalSchoolAudit">
                        <el-select
                            v-model="updForm.externalSchoolAudit"
                            style="width:180px">
                            <el-option
                                v-for="(item,index) in optionsYn"
                                :key="index"
                                :label="item"
                                :value="item">
                            </el-option>
                        </el-select>
                    </el-form-item>
                </el-col>
            </el-form>
        </el-row>
        <el-form :inline="true" :model="updForm" ref="updForm3" label-width="120px" :rules="addRules" v-if="updForm.isSpot == '是'">
            <el-form-item label="点检频次" prop="spotFrequency">
                <!-- Cron表达式：<el-input readonly clearable v-model="updForm.spotFrequency" :style="{ width: inputWid(updForm.spotFrequency) }"/>。 -->
                <div>
                每 <el-input v-model.number="frequency.times" :readonly="frequency.date == '年'?true:false" type="number" style="width:80px" @blur="setSpot('times','upd')"/>
                <el-select
                    v-model="frequency.date"
                    style="width:90px"
                    @change="setSpot('date','upd')">
                    <el-option
                        v-for="(item,index) in optionsDate"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select>
                <el-select
                  v-if="frequency.date === '年'"
                    v-model="value2"
                    style="width:70px"
                    @change="changeMonth"
                    placeholder="月">
                    <el-option
                        v-for="(item,index) in 12"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select>
                <el-select
                  v-if="frequency.date === '年'"
                    v-model="value3"
                    style="width:70px"
                    @change="changeDay"
                    placeholder="日">
                    <el-option
                        v-for="(item,index) in days"
                        :key="index"
                        :label="item"
                        :value="item">
                    </el-option>
                </el-select> 执行一次</div>
            </el-form-item>
        </el-form>
        <el-form :inline="true" :model="updForm" ref="updForm2" label-width="120px">
            <el-form-item label="备注栏">
                <el-input style="width: 350px" clearable type="textarea" :autosize="{ minRows: 1, maxRows: 3}" v-model="updForm.remark" auto-complete="off"></el-input>
            </el-form-item>
        </el-form>

        <!-- 公共底部 -->
        <div slot="footer" class="dialog-footer">
            <el-button @click="showupd = false">取 消</el-button>
            <el-button
            type="primary"
            @click="updprocess('updForm')"
            >保存</el-button
            >
        </div>
    </el-dialog>

   <!-- pagination 分页 -->
    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="listQuery.page"
        :page-sizes="[5,10, 20, 30, 40, 100, 300, 500]"
        :page-size="listQuery.limit"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      ></el-pagination>
    </div>

    <el-divider></el-divider>

    <el-button style="margin-right: 10px" type="success" size="small" @click="hExportExcel">导出数据Excel</el-button>

  </div>
</template>

<script>
import { selfacility,addfacility,updfacility,delfacility,selbarcodeType,printlate } from "@/api/processRoute"
import { getCenter } from '../../api/workSection.js'
import { findUserListGroup } from '../../api/chargingData.js'
export default {
    name: 'frockregister',
    data () {
        return {
          userList:[],
          value2:'', // 月
          value3:'', // 日
          days:30,   // 一个月多少天
            listQuery: {
                page: 1,                                    //页码
                limit: 10                                   //每页多少条记录
            },
            param: {
                processNo: '',                      //工序编号
                processName: '',                           //工序名称
                workCenter: ''                      //工作中心
            },
            total: 0,                                      //数据的总数
            tableInfo: [],
            loadingList: false,
            loading: false,
            centerList: [],                         //工作中心列表
            createForm: {
                spotFrequency: '0 0 0 1/1 * ? '
            },
            updForm: {},
            optionsYn: ['是','否'],      //是否类型
            optionsResourceSourceList: ['外购','自制','租赁','客供'],
            optionsResourceTypeList: ['生产工具','生产设备','检测设备'],
            optionsAccessType: ['出库','入库'],
            // 表单校验
            addRules: {
                facilityBarcodeType1: [
                    { required: true, message: "资源大类不能为空!", trigger: "change" },
                ],
                facilityBarcodeType2: [
                    { required: true, message: "资源小类不能为空!", trigger: "change" },
                ],
                facilityBarcodeType3: [
                    { required: true, message: "资源规格不能为空!", trigger: "change" },
                ],
                facilityBarcodeType4: [
                    { required: true, message: "资源属性不能为空!", trigger: "change" },
                ],
                facilityName: [
                    { required: true, message: "工装名称不能为空!", trigger: "change" },
                ],
                facilityProductionDate: [
                    { required: true, message: "工装生产日期不能为空!", trigger: "change" },
                ],
                upperLimitDate: [
                    { required: true, message: "上限时间不能为空!", trigger: "change" },
                ],
                upperLimitNumber: [
                    { required: true, message: "上限次数不能为空!", trigger: "change" },
                ],
                jobNumber: [
                    { required: true, message: "维护保养人工号不能为空!", trigger: "change" },
                ],
                userName: [
                    { required: true, message: "维护保养人姓名不能为空!", trigger: "change" },
                ],
                acceptanceAudit: [
                    { required: true, message: "验收审核不能为空!", trigger: "change" },
                ],
                accessAudit: [
                    { required: true, message: "出入库审核不能为空!", trigger: "change" },
                ],
                spotAudit: [
                    { required: true, message: "点检审核不能为空!", trigger: "change" },
                ],
                maintenanceAudit: [
                    { required: true, message: "维修审核不能为空!", trigger: "change" },
                ],
                externalSchoolAudit: [
                    { required: true, message: "外校审核不能为空!", trigger: "change" },
                ],
                retirementAudit: [
                    { required: true, message: "报废审核不能为空!", trigger: "change" },
                ],
                isSpot: [
                    { required: true, message: "是否需要点检不能为空!", trigger: "change" },
                ],
                spotFrequency: [
                    { required: true, message: "点检频次不能为空!", trigger: "change" },
                ],
            },
            showAdd: false,
            showupd: false,
            userInfo: this.$store.state.user.userInfo,
            createLoading: false,
            barcodeType1List: [],
            barcodeType2List: [],
            barcodeType3List: [],
            barcodeType4List: [],
            frequency: {
                times: 1,
                date: '天'
            },
            optionsDate: ['年','月','天','小时']
        }
    },
    computed: {
      inputWid() {
        return function (value) {
            if(!value || (value.length <= 10)){
              return '150px'
            } else {
              return (150 + (String(value).length-10)*6) + 'px'
            }
        }
      }
    },
    methods: {
        // 工号发生改变
        jobNumberChange(e,num){
            this.userList.forEach(item => {
                if(item.jobNumber == e){
                  if(num == 2){
                    this.updForm.userName = item.userName
                    this.updForm.phone = item.phone
                  }else {
                    this.createForm.userName = item.userName
                    this.createForm.phone = item.phone
                  }
                }
            })
        },
        // 名字发生改变
        NameChange(e,num){
            this.userList.forEach(item => {
                if(item.userName == e){
                  if(num == 2){
                    this.updForm.jobNumber = item.jobNumber
                    this.updForm.phone = item.phone
                  }else {
                    this.createForm.jobNumber = item.jobNumber
                    this.createForm.phone = item.phone
                  }
                }
            })
        },
        getData(){
          this.listQuery.page = 1
          this.listQuery.limit = 10
          this.handleFilter()
        },
        async handleFilter() {
            this.loadingList = true
            let query = Object.assign({},this.listQuery)
            if(this.param.facilityBarcode){ query.facilityBarcode = this.param.facilityBarcode}
            if(this.param.facilityName){ query.facilityName = this.param.facilityName}
            let data = await selfacility(query)
            let errmsg = data.msg
            this.loadingList = false
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errmsg)
            this.total = data.data.total
            this.tableInfo = data.data.records
            this.tableInfo.forEach(item => {
                item.spotAudit = this.boleanToStr(item.spotAudit)
                item.retirementAudit = this.boleanToStr(item.retirementAudit)
                item.acceptanceAudit = this.boleanToStr(item.acceptanceAudit)
                item.maintenanceAudit = this.boleanToStr(item.maintenanceAudit)
                item.isSpot = this.boleanToStr(item.isSpot)
                item.accessAudit = this.boleanToStr(item.accessAudit)
                item.externalSchoolAudit = this.boleanToStr(item.externalSchoolAudit)
            });
        },
        // table表单下方的页码组件改变每页显示的数据条数
        handleSizeChange(val) {
          this.listQuery.limit = val
          this.handleFilter()
        },
        // table表单下方的页码组件改变页面
        handleCurrentChange(val) {
          this.listQuery.page = val
          this.handleFilter()
        },
        transformDat(res) {
          const mapInfo = {
            index: '序号',
            facilityBarcode: '工装条码',
            facilityName: '工装名称',
            facilityProductionDate: '工装生产日期',
            upperLimitDate: '上限时间',
            cumulativeNumber: '累计次数',
            upperLimitNumber: '上限次数',
            jobNumber: '维护保养人工号',
            userName: '维护保养人姓名',
            type: '结果判定',
            remark: '备注栏',
            resourceSource: '资源来源',
            resourceType: '资源类型',
            acceptanceAudit: '验收审核',
            accessAudit: '出入库审核',
            spotAudit: '点检审核',
            maintenanceAudit: '维修审核',
            externalSchoolAudit: '外校审核',
            retirementAudit: '报废审核',
            isSpot: '是否需要点检',
            spotFrequency: '点检频次',
            createTime: '创建时间',
            updateTime: '修改时间'
          }
          // 对data进行格式化
          // 取出所有的属性名
          const props = Object.keys(res[0]) // ['id','']
          // 将属性名从英文转为中文
          const header = props.map(zhkey => mapInfo[zhkey])
          console.log('中文的表头', header)
          // const data=[['xxxx','总裁办'，'13800000']]
          const data = res.map(obj => Object.values(obj))
          return { header, data }
        },
        // 导出excel
        async hExportExcel() {
          this.loading = true
          let query = Object.assign({},this.listQuery)
          query.page = 1
          query.limit = 10000
          if(this.param.facilityBarcode){ query.facilityBarcode = this.param.facilityBarcode}
          if(this.param.facilityName){ query.facilityName = this.param.facilityName}
          let arr = await selfacility(query)
          if(arr.code == '500') return
          if(arr.code != '1'){
            this.loading = false
            return this.$message.error(errmsg)
          }
          if(!arr.data.records.length) return this.$message.error('暂无数据')
          arr.data.records.forEach(item => {
                item.spotAudit = this.boleanToStr(item.spotAudit)
                item.retirementAudit = this.boleanToStr(item.retirementAudit)
                item.acceptanceAudit = this.boleanToStr(item.acceptanceAudit)
                item.maintenanceAudit = this.boleanToStr(item.maintenanceAudit)
                item.isSpot = this.boleanToStr(item.isSpot)
                item.accessAudit = this.boleanToStr(item.accessAudit)
                item.externalSchoolAudit = this.boleanToStr(item.externalSchoolAudit)
          });
          const { header, data } = this.transformDat(this.setSort(arr.data.records))
          import('@/vendor/Export2Excel').then(excel => {
            // excel表示导入的模块对象
            console.log(excel)
            excel.export_json_to_excel({
            header, // 表头 必填
            data, // 具体数据 必填
            filename: '工序信息表excel', // 文件名称
            autoWidth: true, // 宽度是否自适应
            bookType: 'xlsx' // 生成的文件类型
            })
          })
          this.loading = false
        },
        // 排序函数
        setSort(arr){
          let newArr = JSON.parse(JSON.stringify(arr))
          let arr1 = []
          newArr.forEach((item,index)=>{
            let obj = {
              index: index+1,
              facilityBarcode: item.facilityBarcode,
              facilityName: item.facilityName,
              facilityProductionDate: item.facilityProductionDate,
              upperLimitDate: item.upperLimitDate,
              cumulativeNumber: item.cumulativeNumber,
              upperLimitNumber: item.upperLimitNumber,
              jobNumber: item.jobNumber,
              userName: item.userName,
              type: item.type,
              remark: item.remark,
              resourceSource: item.resourceSource,
              resourceType: item.resourceType,
              acceptanceAudit: item.acceptanceAudit,
              accessAudit: item.accessAudit,
              spotAudit: item.spotAudit,
              maintenanceAudit: item.maintenanceAudit,
              externalSchoolAudit: item.externalSchoolAudit,
              retirementAudit: item.retirementAudit,
              isSpot: item.isSpot,
              spotFrequency: item.spotFrequency,
              createTime: item.createTime,
              updateTime: item.updateTime
            }
            arr1.push(obj)
          })
          return arr1
        },
        cancelSubmit(){
            this.param = {
                facilityBarcode: '',                      //工装条码
                facilityName: '',                           //工装名称
            }
            this.listQuery.page = 1
            this.handleFilter()
        },
        strToBolean(val){
            return val == '是'?true:false
        },
        // 提交表单之前先进行验证
        addprocess(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    if(this.createForm.isSpot == '是'){
                        this.$refs['createForm3'].validate((valid) => {
                            if (valid) {
                                this.submitprocess()
                            }
                        })
                    } else {
                        this.submitprocess()

                    }
                } else {
                    return false
                }
            })
        },
        async submitprocess(){
            if(!this.createForm.phone) return this.$message.error('维护保养人员没有录入电话号码！')
            this.createLoading = true
            setTimeout(() => {
                this.createLoading = false
            }, 12000);
            let query = Object.assign({},this.createForm)
            delete query.phone
            console.log('query',query);
            if(!this.createForm.remark) { query.remark = '' }
            if(this.createForm.isSpot != '是') { delete query.spotFrequency }
            if(!this.createForm.resourceSource) { delete query.resourceSource }
            if(!this.createForm.resourceType) { delete query.resourceType }
            query.spotAudit = this.strToBolean(query.spotAudit)
            query.retirementAudit = this.strToBolean(query.retirementAudit)
            query.acceptanceAudit = this.strToBolean(query.acceptanceAudit)
            query.maintenanceAudit = this.strToBolean(query.maintenanceAudit)
            query.isSpot = this.strToBolean(query.isSpot)
            query.accessAudit = this.strToBolean(query.accessAudit)
            query.externalSchoolAudit = this.strToBolean(query.externalSchoolAudit)
            const data = await addfacility(query)
            const errMsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errMsg)
            this.createLoading = false
            this.$message.success(errMsg)
            this.resetForm()
            this.showAdd = false
            this.handleFilter()
        },
        resetForm(){
             this.$refs.createForm.resetFields();
             this.createForm.spotFrequency = '0 0 0 1/1 * ? '
             this.frequency.times = 1
             this.frequency.date = '天'
        },
        boleanToStr(val){
            return val == 'true'?'是':'否'
        },
        // 打印
        async handlePrint(row){
          console.log(row);
          const res = await printlate({sn:row.facilityBarcode, name: row.facilityName})
          console.log(res);
          this.$message.success('打印成功')
        },
        handleEdit(row){
          // 判断备注是不是字符串null
          if(row.remark === 'null'){
              row.remark = ''
            }
          if(row.spotFrequency === 'null'){
            row.spotFrequency = ''
          }
            this.updForm = Object.assign({},row)
            // console.log(this.updForm.spotFrequency.split(' '),this.updForm.spotFrequency.split(' ')[4])
            if(this.updForm.spotFrequency && this.updForm.spotFrequency !== 'null'){
                let keyList = this.updForm.spotFrequency.split(' ')
                  if(keyList[2] == '0' && !keyList[3].includes('/') && !keyList[4].includes('/')){
                    this.frequency.times = 1
                    this.frequency.date = '年'
                    this.value2 = keyList[4]
                    this.value3 = keyList[3]
                } else if(this.updForm.spotFrequency.split(' ')[2] != '0') {
                    this.frequency.times = this.updForm.spotFrequency.split(' ')[2].split('-')[1]
                    this.frequency.date = '小时'
                } else if(this.updForm.spotFrequency.split(' ')[3] != '0' && this.updForm.spotFrequency.split(' ')[4] == '*') {
                    this.frequency.times = this.updForm.spotFrequency.split(' ')[3].split('/')[1]
                    this.frequency.date = '天'
                } else if(this.updForm.spotFrequency.split(' ')[4] != '0') {
                  this.frequency.times = this.updForm.spotFrequency.split(' ')[4].split('/')[1]
                    this.frequency.date = '月'
                }
              }
              this.userList.forEach(item => {
                if(item.userName == this.updForm.userName && item.jobNumber == this.updForm.jobNumber){
                    this.updForm.phone = item.phone
                }
              })
            // this.frequency.times = this.updForm.spotFrequency.split(' ')[3].split('/')[1]
            // this.$set(this.updForm, 'facilityProductionDate', row.facilityProductionDate)
            this.showupd = true
        },
        // 提交表单之前先进行验证
        updprocess(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    // this.$refs['updForm3'].validate((valid) => {
                        if (valid) {
                            this.updfacility()
                        }
                    // })
                } else {
                    return false
                }
            })
        },
        async updfacility(){
          if(!this.updForm.phone) return this.$message.error('维护保养人员没有录入电话号码！')
          if(this.updForm.isSpot === '否'){ 
            delete this.updForm.spotFrequency
          }
            let query = Object.assign({},this.updForm)
            delete query.createTime
            delete query.updateTime
            delete query.useDate
            delete query.phone
            if(!this.updForm.resourceSource) { delete query.resourceSource }
            if(!this.updForm.resourceType) { delete query.resourceType }
            query.spotAudit = this.strToBolean(query.spotAudit)
            query.retirementAudit = this.strToBolean(query.retirementAudit)
            query.acceptanceAudit = this.strToBolean(query.acceptanceAudit)
            query.maintenanceAudit = this.strToBolean(query.maintenanceAudit)
            query.isSpot = this.strToBolean(query.isSpot)
            query.accessAudit = this.strToBolean(query.accessAudit)
            query.externalSchoolAudit = this.strToBolean(query.externalSchoolAudit)
            const data = await updfacility(query)
            const errMsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errMsg)
            this.$message.success(errMsg)
            this.showupd = false
            this.handleFilter()
        },
        // 获取工作中心
        async getCenterList() {
          let {data} = await getCenter()
          this.centerList = data
        },
        handleDelete(row,index) {
            this.$confirm('这将会永久删除该行数据，是否继续?', '警告', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                this.delprocess(row,index)
            }).catch(() => {
                this.$message({
                  type: 'info',
                  message: '已取消删除'
                })
            })
        },
        async delprocess(row,index){
          let res = await delfacility({facilityBarcode: row.facilityBarcode})
          if(res.code == '500') return
          if(res.code != '1') return this.$message.error(res.msg)
          this.tableInfo.splice(index,1)
          this.$message.success(res.msg)
        },
        async getBarcodeType(type) {
            this.loadingList = true
            let query = {
                facilityBarcodeType: type,
                page: 1,
                limit: 10000
            }
            let data = await selbarcodeType(query)
            let errmsg = data.msg
            if(data.code == '500') return
            if(data.code != '1') return this.$message.error(errmsg)
            if(type == '大类'){
                this.barcodeType1List = data.data.records
            } else if(type == '小类') {
                this.barcodeType2List = data.data.records
            } else if(type == '规格') {
                this.barcodeType3List = data.data.records
            } else if(type == '属性') {
                this.barcodeType4List = data.data.records
            }
            this.loadingList = false
        },
        // 月发生改变
        changeMonth(){
          if(this.value2 == 2){
            this.days = 28  // 如果是2月，就只有28天
          } else {
            this.days = 30
          }
          this.value3 = ''
          let keyList = this.updForm.spotFrequency.split(' ')
          keyList[4] = this.value2.toString()
          console.log(keyList);
          this.updForm.spotFrequency = keyList.join(' ')
          this.createForm.spotFrequency =  keyList.join(' ')
        },
        // 日发生改变
        changeDay(){
          let keyList = this.updForm.spotFrequency.split(' ')
          keyList[3] = this.value3.toString()
          console.log(keyList);
          this.updForm.spotFrequency = keyList.join(' ')
          this.createForm.spotFrequency =  keyList.join(' ')
        },
        setSpot(type,action){
            if(this.frequency.times<1) this.frequency.times = 1
            if(this.frequency.times>12 && this.frequency.date == '月') this.frequency.times = 12
            if(this.frequency.times>31 && this.frequency.date == '天') this.frequency.times = 31
            if(this.frequency.times>23 && this.frequency.date == '小时') this.frequency.times = 23
            if(type == 'date') { this.frequency.times = 1 }
            let index = 3
            if(this.frequency.date == '年'){
                // index = 6
                if(action == 'upd' && type == 'date'){
                     this.updForm.spotFrequency = '0 0 0 1 1 ?'
                } else { this.createForm.spotFrequency = '0 0 0 1 1 ?' }
            } else if(this.frequency.date == '月'){
                index = 4
                if(action == 'upd' && type == 'date'){
                     this.updForm.spotFrequency = '0 0 0 1 1/1 ? '
                } else { this.createForm.spotFrequency = '0 0 0 1 1/1 ? ' }
            } else if(this.frequency.date == '天'){
                index = 3
                if(action == 'upd' && type == 'date'){
                     this.updForm.spotFrequency = '0 0 0 1/1 * ? '
                } else { this.createForm.spotFrequency = '0 0 0 1/1 * ? ' }
            } else if(this.frequency.date == '小时'){
                index = 2
                if(action == 'upd' && type == 'date'){
                     this.updForm.spotFrequency = '0 0 0-1 * * ? '
                } else { this.createForm.spotFrequency = '0 0 0-1 * * ? ' }
            }
            console.log(this.createForm.spotFrequency)
            let keyList = action == 'upd'?this.updForm.spotFrequency.split(' '):this.createForm.spotFrequency.split(' ')
            console.log('keyList',keyList)
            if(this.frequency.date != '年'){
                let str1 = []
                if(this.frequency.date == '小时'){
                    str1 = keyList[index].split('-')
                } else { str1 = keyList[index].split('/') }
                str1[1] = this.frequency.times
                str1[0] = this.frequency.date == '小时'?0:1
                if(this.frequency.date == '小时'){
                    keyList[index] = str1.join('-')
                } else { keyList[index] = str1.join('/') }
            } else {
                // keyList[index] = '*'
                this.value2 = ''
                this.value3 = ''
                this.createForm.spotFrequency = '0 0 0 1 1 ? *'
            }
            if(action == 'upd'){
                this.updForm.spotFrequency = keyList.join(' ')
            } else {
                this.createForm.spotFrequency = keyList.join(' ')
            }
            console.log(keyList.join(' '))
        },
        // 获取所有人信息
        async getuserPage(){
            let query = {
                page:1,
                limit:9999,
                status:1
            }
            const res = await findUserListGroup(query)
            this.userList = res.data.records
        }
    },
    // 进入页面获取table信息
    mounted() {
        this.handleFilter()
        this.getuserPage()
    }
}
</script>

<style>

.btn-add{
    margin-bottom: 28px;
}

.ul-item{
  width: 85%;
}
</style>
